package com.example.newwork

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.ViewModelProvider
import com.alibaba.android.arouter.facade.annotation.Route
import com.android.baselibrary.arouter.ArouterContains
import com.android.baselibrary.base.BaseActivity
import com.example.newwork.databinding.NetActivityMainBinding

@Route(path = ArouterContains.NETWORK_MODEL)
class NetWorkMainActivity :BaseActivity<NetActivityMainBinding>(){
    private val viewModel by lazy {
        ViewModelProvider(this)[NetViewModel::class.java]
    }
    private val serviceLiveData by lazy {
        getLiveDataService(MainApi::class.java)
    }
    override fun getLayoutId(): Int {
       return R.layout.net_activity_main
    }

    override fun initView() {
        mBinding.viewModel = viewModel
        mBinding.lifecycleOwner = this
        viewModel.listData.observe(this){
            when(it){
                is NetResource.doLoading ->{
                    Log.i("TAGaa", "initView: doLoading")
                }
                is NetResource.doSuccess ->{
                    Log.i("TAGaa", "initView: doSuccess")
                }
                is NetResource.doFailure ->{
                    Log.i("TAGaa", "initView: doFailure")
                }
            }
        }
    }

    override fun initListener() {
        mBinding.btnLivedata.setOnClickListener {
            viewModel.startIntentEvents(NetWorkEvent.RemoteDataByLiveData)
        }
        mBinding.btnCommon.setOnClickListener {
            viewModel.startIntentEvents(NetWorkEvent.RemoteDataByCommon)
        }
        mBinding.btnFlow.setOnClickListener {
            viewModel.startIntentEvents(NetWorkEvent.RemoteDataByFlow)
        }

    }

}